<?php
if(!defined('access')) {
echo 'You cannot access this file directly.';
exit();
}
if ($this->Jukebox_Size != null){
    $sub_language = $this->Jukebox_Size;
} else {
if(!$this->read_config('sub_language')){
$sub_language = "en";
} else {
    $sub_language = $this->read_config('sub_language');
}
}
$rss_header = '<?xml version="1.0" ?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">

<bookmark>Subtitle Download</bookmark>';
$rss_onenter = '<onEnter>
	pageTitle = getPageInfo("pageTitle");
	infoStr = "Please Wait";
	setScreenSaverStatus("no");
	setRefreshTime(100);
</onEnter>';
$rss_onexit = '<onExit>
	setScreenSaverStatus("yes");
	setRefreshTime(-1);
</onExit>';
$rss_onrefresh = '<onRefresh>
	redrawDisplay();
	comm = readStringFromFile("/usr/local/etc/subs_comm");
        if ( comm != null ){
	infoStr = comm; }
        else {
        infoStr += ".";
        }
</onRefresh>';
$rss_mdis_header = '<mediaDisplay
	name=onePartView
	itemPerPage=1
	viewAreaXPC=1.3
	viewAreaYPC=1.3
	viewAreaWidthPC=99.5
	viewAreaHeightPC=99.5

	itemXPC=20
	itemYPC=82
	itemWidthPC=50
	itemHeightPC=8
	itemImageXPC=25
	itemImageYPC=67.0
	itemImageWidthPC=50
	itemImageHeightPC=12.1

	imageFocus=""

	sideColorRight=-1:-1:-1
	sideColorLeft=-1:-1:-1
	sideColorTop=-1:-1:-1
	sideColorBottom=-1:-1:-1
	backgroundColor=-1:-1:-1
	focusBorderColor=-1:-1:-1
	unFocusBorderColor=-1:-1:-1
	itemBackgroundColor=-1:-1:-1
	showHeader="no"
	showDefaultInfo="no"
>
<backgroundDisplay>
	<image offsetXPC=0 offsetYPC=0 widthPC=100 heightPC=100 useBackgroundSurface="yes">
		./setup_menu/image/setup_popup_bg.fsp
	</image>
</backgroundDisplay>';
$rss_text_header = '<text offsetXPC=8.8 offsetYPC=3.1 widthPC=83.5 heightPC=18.4 fontSize=18 align=center backgroundColor=-1:-1:-1 foregroundColor=255:255:255 >
	<script>';
$rss_text = 'header = "Subtitle Downloader"; ';
$rss_text_footer = 'header;
	</script>
</text>';
$rss_info_header = '<text redraw=yes offsetXPC=7 offsetYPC=15 widthPC=87 heightPC=70 fontSize=14 align=left lines=22 >
	<script>';
//$rss_info = 'infoStr = "";';
$rss_info_footer = 'infoStr;
    </script>
</text>';
$rss_itemdisplay = '<itemDisplay>
	<image offsetXPC=0 offsetYPC=0 widthPC=100 heightPC=100>
		<script>
			image = "";
			queryIndex = getQueryItemIndex();
			focusIndex = getFocusItemIndex();
			if (queryIndex == focusIndex) {
				image = "./setup_menu/image/398_focus.fsp";
			}
			image;
		</script>
	</image>
	<text offsetXPC=5 offsetYPC=5 widthPC=90 heightPC=90 align=center fontSize=16 backgroundColor=-1:-1:-1>
		<foregroundColor>
			<script>
				fgcolor = "255:255:255";
				queryIndex = getQueryItemIndex();
				focusIndex = getFocusItemIndex();
				data = getStringArrayAt(popupOptions, queryIndex);
				if (queryIndex == focusIndex) {
					fgcolor = "0:153:255";
				}
				fgcolor;
			</script>
		</foregroundColor>
		<script>
			title = getItemInfo("title");
			title;
		</script>
	</text>
</itemDisplay>';
$rss_onuserinput = '<onUserInput>
	handle = "false";
	userInput = currentUserInput();
	if ( "enter" == userInput || "return" == userInput ) {
			handle = "return";
		} else { handle = "true"; }
	else if ("right" == userInput || "left" == userInput) {
		handle = "true";
	}
	handle;
</onUserInput>';
$rss_mdis_footer = '</mediaDisplay>';
$rss_channel_footer = '<channel>
	<link>http://127.0.0.1/srjg.php</link>';
$rss_item_footer = '<item>
<title>
<script>';
$rss_title = 'title = "Return"; ';
$rss_finale = 'title;
</script></title>
</item>
</channel>
</rss>';
        exec("/usr/bin/busybox pgrep python", $output, $pids);
            if($pids == 0) {
                $rss_text = 'header = "Download in progress"; ';
                echo $rss_header.$rss_onenter.$rss_onexit.$rss_onrefresh.$rss_mdis_header.$rss_text_header.$rss_text.$rss_text_footer.$rss_info_header.$rss_info_footer.$rss_itemdisplay.$rss_onuserinput.$rss_mdis_footer.$rss_channel_footer.$rss_item_footer.$rss_title.$rss_finale;
            } 
            else {
                @unlink("/usr/local/etc/subs_comm");
                $name_arg = escapeshellarg($this->category_title);
                //file_put_contents("/usr/local/etc/test3.txt", $name_arg);
                //exec("/usr/bin/busybox nohup /opt/local/bin/subliminal -f -l $sub_language -c /usr/local/etc/subliminal.tmp $name_arg > /usr/local/etc/subs_comm 2>&1 &");
                exec("/usr/bin/busybox nohup /usr/local/etc/Periscope/periscope -f -l $sub_language -l en --cache-folder /usr/local/etc/Periscope --lang-in-name $name_arg > /usr/local/etc/subs_comm 2>&1 &");
                $rss_text = 'header = "Subtitle Downloader"; ';
                $rss_title = 'title = "Wait for the script to end"; ';
                echo $rss_header.$rss_onenter.$rss_onexit.$rss_onrefresh.$rss_mdis_header.$rss_text_header.$rss_text.$rss_text_footer.$rss_info_header.$rss_info_footer.$rss_itemdisplay.$rss_onuserinput.$rss_mdis_footer.$rss_channel_footer.$rss_item_footer.$rss_title.$rss_finale;
            }
